﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

namespace SinhNhat
{
    public class BasePage : Page
    {
        private string _SiteRoot;

        public string SiteRoot
        {
            get
            {
                if(_SiteRoot == null || _SiteRoot.Equals(string.Empty))
                {
                    _SiteRoot = "http://" + Request.Url.Authority + "/";
                }
                return _SiteRoot;
            }
        }

        public bool IsAdmin()
        {
            if (Session["account"] == null)
            {
                return false;
            }

            return true;
        }

        protected void SetupColumnCss(bool showRight)
        {
            Panel pnLeft = (Panel)Master.FindControl("pnLeft");
            Panel pnRight = (Panel)Master.FindControl("pnRight");

            if (pnLeft == null) return;
            if (pnRight == null) return;

            if (!showRight)
            {
                pnLeft.CssClass = "left2";
                pnRight.CssClass = "right2";
            }
            else
            {
                pnLeft.CssClass = "left1";
                pnRight.CssClass = "right1";
            }
        }

        protected void SetupCss(List<string> cssLinks)
        {
            Literal lrCss = (Literal)Master.FindControl("lrCss");
            if (lrCss == null) return;

            string html = string.Empty;
            foreach (string cssLink in cssLinks)
            {
                html += "<link rel=\"stylesheet\" href=\"../data/css/" + cssLink + "\" type=\"text/css\" charset=\"utf-8\" />";
            }

            lrCss.Text = html;
        }

        protected void SetupJs(List<string> jsLinks)
        {
            Literal lrJs = (Literal)Master.FindControl("lrJs");
            if (lrJs == null) return;

            string html = string.Empty;
            foreach (string jsLink in jsLinks)
            {
                html += "<script src=\"../data/js/" + jsLink + " \" type=\"text/javascript\"></script>";
            }

            lrJs.Text = html;
        }
    }
}
